<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: autocomplete.php 361 2013-12-02 17:29:37Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 361 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-12-02 17:29:37 +0000 (Mon, 02 Dec 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright © since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	© 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	© 2002-2003 osCommerce - www.oscommerce.com
* 	© 2003     nextcommerce - www.nextcommerce.org
* 	© 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

chdir('../../../');
include('includes/application_top.php');

$term = urlencode(preg_replace('/[^a-zA-Z0-9-]/u', ' ', $_GET['term']));

$results = $db->db_query("SELECT 
								pd.products_id,
								pd.products_name,
								p.products_image
							FROM 
								".TABLE_PRODUCTS_DESCRIPTION." pd
								LEFT JOIN ".TABLE_PRODUCTS." AS p ON (p.products_id = pd.products_id)
							WHERE 
								pd.products_name REGEXP '".$term."' 
	 						AND
							  p.products_status = 1
  						AND
								pd.language_id = '".(int)$_SESSION['languages_id']."'
							LIMIT 20");

if($results->_numOfRows) {
	while(!$results->EOF) {
		$products[] = array('name' => $results->fields['products_name'], 
							'id' => $results->fields['products_id'],
							'img' => DIR_WS_ICON_IMAGES.$results->fields['products_image'],
							'price' => $price->GetPrice($results->fields['products_id']));
		$results->MoveNext();
	}
	echo json_encode($products);
}